'use strict';
var allTestFiles = [];
var TEST_REGEXP = /spec\.js$/i;

var pathToModule = function(path) {
    return path.replace(/^\/base\//, '').replace(/\.js$/, '');
};

Object.keys(window.__karma__.files).forEach(function(file) {
    if (TEST_REGEXP.test(file)) {  
        // Normalize paths to RequireJS module names.
        allTestFiles.push(pathToModule(file));
    }    
});

require.config({   
    baseUrl: '/base',

    paths: {        
        'angular': 'app/bower_components/angular/angular',    
        'angularRoute': 'app/bower_components/angular-route/angular-route',  
        'angularResource': 'app/bower_components/angular-resource/angular-resource',
        'angularMocks': 'app/bower_components/angular-mocks/angular-mocks',
        'jquery' : 'app/bower_components/jquery/dist/jquery',  
        'jscrollpanel': 'app/js/lib/jquery.jscrollpane',
        'i18n' : 'app/js/lib/i18next-1.6.0.min',
        '_' : 'app/js/lib/lodash',  
        'WebPDF' : 'app/js/WebPDF',      
    },
    shim: {
        'jquery' :{
            'exports' : '$'
        },
        'jscrollpanel' : {
            'deps': ['jquery'],
        },
        'angular': {
            'deps': ['jquery'],
            'exports': 'angular'
        },        
        'angularResource' : {
            'deps': ['angular'],
            'exports': 'angular.resource'
        },
        'angularMocks': {
            'deps': ['angular'],
            'exports': 'angular.mock'
        },
        'WebPDF': {
            'deps' : ['angular', 'angularResource', 'jquery', 'jscrollpanel', '_', 'i18n'],           
        },
        priority: [
            "angular", '_'
        ],
    },
    packages : ["app/js/PDFView", "app/js/Plugins/Form", "Plugins/Hand", "Plugins/Annot"],
    deps: allTestFiles,
    callback: window.__karma__.start
});

require([        
        'WebPDF',     
        "./app/js/PDFConfigProvider",
        "./app/js/PDFApiProvider"     
    ],
    function(WebPDF) {
        var s3Key = 'doc-1';

        WebPDF.config(['PDFConfigProvider', 'PDFApiProvider',  function(PDFConfigProvider, PDFApiProvider) {         
            PDFConfigProvider._s3Key = s3Key;            
            PDFConfigProvider._baseUrl  = '/app/pdfdata/';  
            PDFApiProvider.pdfViewer = $("body");
        }]);     
    });




